package com.untour.seqid.config.leaf.segment.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.untour.seqid.config.leaf.segment.domain.LeafAllocDO;
import org.apache.ibatis.annotations.*;

import java.util.Set;

public interface LeafAllocMapper extends BaseMapper<LeafAllocDO> {
    @Update("UPDATE leaf_alloc SET max_id = max_id + step WHERE biz_tag = #{bizTag}")
    int updateMaxId(@Param("bizTag") String bizTag);

    @Select("SELECT biz_tag FROM leaf_alloc")
    Set<String> queryAllBizTags();

    @Select("SELECT biz_tag, max_id, step FROM leaf_alloc WHERE biz_tag = #{bizTag}")
    @Results(value = {
            @Result(column = "biz_tag", property = "bizTag"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step")
    })
    LeafAllocDO getLeafAlloc(@Param("bizTag") String bizTag);

    @Update("UPDATE leaf_alloc SET max_id = max_id + #{step} WHERE biz_tag = #{bizTag}")
    void updateMaxIdByCustomStep(@Param("bizTag") String bizTag,@Param("step") int step);

}
